package com.oscar.helper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

public class IntuireDateTime {
	public IntuireDateTime() {
	}
	private String displayFormatDateTime = "";
	private String saveFormatDateTime = "";
	SimpleDateFormat sdf;
	SimpleDateFormat xmlSdf;
	private Calendar myCalendar = Calendar.getInstance();
	
	public String getDisplayFormatDateTime() {
		return displayFormatDateTime;
	}
	public void setDisplayFormatDateTime(String displayFormatDateTime) {
		this.displayFormatDateTime = displayFormatDateTime;
	}
	public String getSaveFormatDateTime() {
		return saveFormatDateTime;
	}
	public void setSaveFormatDateTime(String saveFormatDateTime) {
		this.saveFormatDateTime = saveFormatDateTime;
	}
	public SimpleDateFormat getSdf() {
		return sdf;
	}
	public void setSdf(SimpleDateFormat sdf) {
		this.sdf = sdf;
	}
	public SimpleDateFormat getXmlSdf() {
		return xmlSdf;
	}
	public void setXmlSdf(SimpleDateFormat xmlSdf) {
		this.xmlSdf = xmlSdf;
	}
	public Calendar getMyCalendar() {
		return myCalendar;
	}
	public void setMyCalendar(Calendar myCalendar) {
		this.myCalendar = myCalendar;
	}
	public IntuireDateTime(String DisplayFormatDateTime, String SaveFormatDateTime)
	{
		this.displayFormatDateTime = DisplayFormatDateTime;
		this.displayFormatDateTime = SaveFormatDateTime;
		sdf =  new SimpleDateFormat(displayFormatDateTime, Locale.US);
		xmlSdf = new SimpleDateFormat(saveFormatDateTime, Locale.US);;
	}
	public void setTimeForCalendar(int date, int month, int year)
	{
		myCalendar.set(Calendar.YEAR, date);
		myCalendar.set(Calendar.MONTH, month);
		myCalendar.set(Calendar.DAY_OF_MONTH, year);
	}
	
	public Date getTimeFromCalendar()
	{
		return myCalendar.getTime();
	}
	public String getStringTimeForDisplay(){
		return sdf.format(myCalendar.getTime());
	}
	public String getStringTimeForSave(){
		return xmlSdf.format(myCalendar.getTime());
	}
	public Date getDateFromStringDisplay(String sDisplay){
		try {
			return sdf.parse(sDisplay);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
			
		}
	}
	public Date getDateBeForeDay(Date day, int numberDay){
		myCalendar.setTime(day);
		myCalendar.add(Calendar.DAY_OF_YEAR,-numberDay);
		return myCalendar.getTime();
	}
	public Date getDateFromStringSave(String sSave){
		try {
			return xmlSdf.parse(sSave);
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
			
		}
	}
}
